CC = gcc
CFLAGS = -Wall -O2
INCLUDE_FLAGS = -I/usr/local/Ascend/ascend-toolkit/latest/include
LDFLAGS = -L/usr/local/Ascend/ascend-toolkit/latest/lib64 -lascendcl

# Add new programs here
PROGRAMS = pcie_p2p_uni pcie_cpu_uni pcie_hybrid_uni

# Common sources and headers
COMMON_SRCS = buffer.c
COMMON_OBJS = $(COMMON_SRCS:.c=.o)
HEADERS = common.h buffer.h

.PHONY: all clean

all: $(PROGRAMS)

$(PROGRAMS): %: %.o $(COMMON_OBJS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

%.o: %.c $(HEADERS)
	$(CC) $(CFLAGS) $(INCLUDE_FLAGS) -c $< -o $@

clean:
	rm -f $(PROGRAMS) *.o
